﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using SubSonic;

namespace SurveyHost.Core.DAL
{
    partial class StemController
    {
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public StemCollection GetSortedCollection()
        {
            Query q = new Query(Tables.Stem);
            q.ORDER_BY(Stem.Columns.MeasureName + " Asc, "
                + Stem.Columns.Rank
                + " Desc");

            return new StemController()
                .FetchByQuery(q);
            
            //return
            //    new StemCollection()
            //        .OrderByDesc(Stem.Columns.Rank)
            //        .OrderByAsc(Stem.Columns.MeasureName)
            //        .Load();
        }

        [DataObjectMethod(DataObjectMethodType.Update, false)]
        public void Update(Stem item)
        {
            item.MarkOld();
            item.Save();
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public void Delete(Stem item)
        {
            new StemController().Destroy(item.StemId, item.StemId);
        }

        [DataObjectMethod(DataObjectMethodType.Insert, true)]
        public void Add(Stem item)
        {
            item.Save();
        }

    }
}
